#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <aclconio.h>
#include <define.h>
#include <transact.h>
#include <tran.h>
#include <gds.h>
#include <sizes.h>
#include "ConfProto.h"
#include "tblutil.h"
#include <\SOFTPAY\Ver30\source\include\sizes.h>
#include <\SOFTPAY\Ver30\HostSrc\citisrc\citiids.h>
#include <\SOFTPAY\Ver30\HostSrc\cpacsrc\cpacids.h>
#include <confio.h>

#include <\SOFTPAY\Ver30\source\include\TCP.h>



static void *storeFromStruct;

static int recordNum;
void registerTCP(void *ptr)
{
	 storeFromStruct = ptr;
}

void *dealWithAddressBoundary(void*address);
int	inLoadTCPRecFromStruct (int inRecNumber, void *vdStruct)
{
	int inRet;
	char* tmp = (char*)vdStruct;

	registerTCP(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inLoadConfRec(TCP_FILENAME, SIZE_TCP_REC, inRecNumber, vdStruct);

	recordNum = inRecNumber;
	return inRet;
}

void vdRestoreTCPRecFromStruct(void *vdStruct)
{
	registerTCP(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	memcpy((char *) pvdGetTCPRec(), vdStruct, SIZE_TCP_REC);

}

void vdCopyTCPRecFromStruct(void *vdStruct)
{
	registerTCP(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
		memcpy(vdStruct, (char *) pvdGetTCPRec(), SIZE_TCP_REC);

}

int	inSaveTCPRecFromStruct (int inRecNumber,  void *vdStruct)
{
	int inRet;

	registerTCP(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(TCP_FILENAME, SIZE_TCP_REC, inRecNumber, (char *) vdStruct);

	return inRet;
}

int	inUpdateTCPRecFromStruct (void *vdStruct)
{
	int inRet;

	registerTCP(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(TCP_FILENAME, SIZE_TCP_REC, recordNum, (char *) vdStruct);

	return inRet;
}

char* szGetHostPrimaryIPFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetHostPrimaryIP();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((TCP_REC*)vdStruct)->szHostPrimaryIP;
}

void vdSetHostPrimaryIPFromStruct(const char* szHostPrimaryIP, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetHostPrimaryIP(szHostPrimaryIP);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((TCP_REC*)vdStruct)->szHostPrimaryIP, szHostPrimaryIP, sizeof(((TCP_REC*)NULL)->szHostPrimaryIP)-1);
}

char* szGetHostSecondaryIPFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetHostSecondaryIP();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((TCP_REC*)vdStruct)->szHostSecondaryIP;
}

void vdSetHostSecondaryIPFromStruct(const char* szHostSecondaryIP, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetHostSecondaryIP(szHostSecondaryIP);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((TCP_REC*)vdStruct)->szHostSecondaryIP, szHostSecondaryIP, sizeof(((TCP_REC*)NULL)->szHostSecondaryIP)-1);
}

char* szGetMyIPFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetMyIP();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((TCP_REC*)vdStruct)->szMyIP;
}

void vdSetMyIPFromStruct(const char* szMyIP, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetMyIP(szMyIP);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((TCP_REC*)vdStruct)->szMyIP, szMyIP, sizeof(((TCP_REC*)NULL)->szMyIP)-1);
}

char* szGetGateWayFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetGateWay();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((TCP_REC*)vdStruct)->szGateWay;
}

void vdSetGateWayFromStruct(const char* szGateWay, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetGateWay(szGateWay);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((TCP_REC*)vdStruct)->szGateWay, szGateWay, sizeof(((TCP_REC*)NULL)->szGateWay)-1);
}

char* szGetSubNetMaskFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetSubNetMask();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((TCP_REC*)vdStruct)->szSubNetMask;
}

void vdSetSubNetMaskFromStruct(const char* szSubNetMask, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetSubNetMask(szSubNetMask);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((TCP_REC*)vdStruct)->szSubNetMask, szSubNetMask, sizeof(((TCP_REC*)NULL)->szSubNetMask)-1);
}

char* szGetHostDNS1FromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetHostDNS1();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((TCP_REC*)vdStruct)->szHostDNS1;
}

void vdSetHostDNS1FromStruct(const char* szHostDNS1, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetHostDNS1(szHostDNS1);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((TCP_REC*)vdStruct)->szHostDNS1, szHostDNS1, sizeof(((TCP_REC*)NULL)->szHostDNS1)-1);
}

char* szGetHostDNS2FromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetHostDNS2();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((TCP_REC*)vdStruct)->szHostDNS2;
}

void vdSetHostDNS2FromStruct(const char* szHostDNS2, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetHostDNS2(szHostDNS2);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((TCP_REC*)vdStruct)->szHostDNS2, szHostDNS2, sizeof(((TCP_REC*)NULL)->szHostDNS2)-1);
}

char* szGetWiFiSysIDFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetWiFiSysID();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((TCP_REC*)vdStruct)->szWiFiSysID;
}

void vdSetWiFiSysIDFromStruct(const char* szWiFiSysID, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetWiFiSysID(szWiFiSysID);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((TCP_REC*)vdStruct)->szWiFiSysID, szWiFiSysID, sizeof(((TCP_REC*)NULL)->szWiFiSysID)-1);
}

char* szGetWiFiWEPKeyVal1FromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetWiFiWEPKeyVal1();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((TCP_REC*)vdStruct)->szWiFiWEPKeyVal1;
}

void vdSetWiFiWEPKeyVal1FromStruct(const char* szWiFiWEPKeyVal1, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetWiFiWEPKeyVal1(szWiFiWEPKeyVal1);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((TCP_REC*)vdStruct)->szWiFiWEPKeyVal1, szWiFiWEPKeyVal1, sizeof(((TCP_REC*)NULL)->szWiFiWEPKeyVal1)-1);
}

char* szGetWiFiWEPKeyVal2FromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetWiFiWEPKeyVal2();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((TCP_REC*)vdStruct)->szWiFiWEPKeyVal2;
}

void vdSetWiFiWEPKeyVal2FromStruct(const char* szWiFiWEPKeyVal2, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetWiFiWEPKeyVal2(szWiFiWEPKeyVal2);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((TCP_REC*)vdStruct)->szWiFiWEPKeyVal2, szWiFiWEPKeyVal2, sizeof(((TCP_REC*)NULL)->szWiFiWEPKeyVal2)-1);
}

char* szGetWiFiWEPKeyVal3FromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetWiFiWEPKeyVal3();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((TCP_REC*)vdStruct)->szWiFiWEPKeyVal3;
}

void vdSetWiFiWEPKeyVal3FromStruct(const char* szWiFiWEPKeyVal3, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetWiFiWEPKeyVal3(szWiFiWEPKeyVal3);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((TCP_REC*)vdStruct)->szWiFiWEPKeyVal3, szWiFiWEPKeyVal3, sizeof(((TCP_REC*)NULL)->szWiFiWEPKeyVal3)-1);
}

char* szGetWiFiWEPKeyVal4FromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetWiFiWEPKeyVal4();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((TCP_REC*)vdStruct)->szWiFiWEPKeyVal4;
}

void vdSetWiFiWEPKeyVal4FromStruct(const char* szWiFiWEPKeyVal4, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetWiFiWEPKeyVal4(szWiFiWEPKeyVal4);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((TCP_REC*)vdStruct)->szWiFiWEPKeyVal4, szWiFiWEPKeyVal4, sizeof(((TCP_REC*)NULL)->szWiFiWEPKeyVal4)-1);
}

short inGetIPTypeFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return inGetIPType();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((TCP_REC*)vdStruct)->inIPType;
}

void vdSetIPTypeFromStruct(short inIPType, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetIPType(inIPType);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((TCP_REC*)vdStruct)->inIPType = inIPType;
}

short inGetIPEnableFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return inGetIPEnable();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((TCP_REC*)vdStruct)->inIPEnable;
}

void vdSetIPEnableFromStruct(short inIPEnable, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetIPEnable(inIPEnable);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((TCP_REC*)vdStruct)->inIPEnable = inIPEnable;
}

short inGetIPTCPTOFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return inGetIPTCPTO();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((TCP_REC*)vdStruct)->inIPTCPTO;
}

void vdSetIPTCPTOFromStruct(short inIPTCPTO, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetIPTCPTO(inIPTCPTO);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((TCP_REC*)vdStruct)->inIPTCPTO = inIPTCPTO;
}

short inGetWiFiICResetFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return inGetWiFiICReset();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((TCP_REC*)vdStruct)->inWiFiICReset;
}

void vdSetWiFiICResetFromStruct(short inWiFiICReset, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetWiFiICReset(inWiFiICReset);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((TCP_REC*)vdStruct)->inWiFiICReset = inWiFiICReset;
}

short shGetIPPortFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return shGetIPPort();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((TCP_REC*)vdStruct)->shIPPort;
}

void vdSetIPPortFromStruct(short shIPPort, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetIPPort(shIPPort);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((TCP_REC*)vdStruct)->shIPPort = shIPPort;
}

short shGetIPTriesFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return shGetIPTries();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((TCP_REC*)vdStruct)->shIPTries;
}

void vdSetIPTriesFromStruct(short shIPTries, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetIPTries(shIPTries);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((TCP_REC*)vdStruct)->shIPTries = shIPTries;
}

short shGetIPPingMinsFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return shGetIPPingMins();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((TCP_REC*)vdStruct)->shIPPingMins;
}

void vdSetIPPingMinsFromStruct(short shIPPingMins, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetIPPingMins(shIPPingMins);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((TCP_REC*)vdStruct)->shIPPingMins = shIPPingMins;
}

short shGetWiFiChannelFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return shGetWiFiChannel();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((TCP_REC*)vdStruct)->shWiFiChannel;
}

void vdSetWiFiChannelFromStruct(short shWiFiChannel, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetWiFiChannel(shWiFiChannel);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((TCP_REC*)vdStruct)->shWiFiChannel = shWiFiChannel;
}

short shGetWiFiWEPModeFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return shGetWiFiWEPMode();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((TCP_REC*)vdStruct)->shWiFiWEPMode;
}

void vdSetWiFiWEPModeFromStruct(short shWiFiWEPMode, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetWiFiWEPMode(shWiFiWEPMode);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((TCP_REC*)vdStruct)->shWiFiWEPMode = shWiFiWEPMode;
}

short shGetWiFiWEPIndexFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return shGetWiFiWEPIndex();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((TCP_REC*)vdStruct)->shWiFiWEPIndex;
}

void vdSetWiFiWEPIndexFromStruct(short shWiFiWEPIndex, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetWiFiWEPIndex(shWiFiWEPIndex);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((TCP_REC*)vdStruct)->shWiFiWEPIndex = shWiFiWEPIndex;
}

